package site.psvm.phoneinfo.common.util;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Resp<T> {
    private String code;
    private String msg;
    private T data;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> Resp<T> ok(T data){
        Resp<T> resp = new Resp<T>();
        resp.setCode("001");
        resp.setMsg("操作成功");
        resp.setData(data);
        return resp;
    }

    public static <T>Resp<T> error(String...msg){
        Resp<T> resp = new Resp<T>();
        resp.setCode("001");
        if (msg==null||msg.length==0) {
            resp.setMsg("操作失败");
        }else {
            resp.setMsg(msg[0]);
        }
        return resp;
    }
}
